package com.jushu.storbox.view.viewImpl;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jushu.storbox.R;


public class TranslateView extends FrameLayout {

	private LayoutParams ViewParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
	private LayoutInflater inflater = null;

	private RelativeLayout rlNotComplaeList = null;
	private RelativeLayout rlHasComplaeList = null;
	private ListView contentListView = null;
	private TextView translateFinishedTextView;
	private TextView translateNotFinishedTextView;
	
	public TranslateView(Context context) {
		super(context);
		initView(context);
	}

	public TranslateView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}

	public TranslateView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	private void initView(Context context) {
		inflater = LayoutInflater.from(context);
		addView(loadFromXml(context), ViewParams);
	}
	
	private View loadFromXml(Context context) {
		View view = inflater.inflate(R.layout.translate_main_view, null, false);
		rlHasComplaeList = (RelativeLayout) view.findViewById(R.id.translate_complate_list_rl);
		rlNotComplaeList = (RelativeLayout) view.findViewById(R.id.translate_finished_list_rl);
		contentListView = (ListView) view.findViewById(R.id.translate_container_id);
		translateFinishedTextView = (TextView) view.findViewById(R.id.translate_complate_tv);
		translateNotFinishedTextView = (TextView) view.findViewById(R.id.translate_not_finished_tv);
		return view;
	}
	
	public void setComplateClickListener(OnClickListener complateClickListener) {
		rlHasComplaeList.setOnClickListener( complateClickListener);
	}
	
	public void setTranslateClickListener(OnClickListener translateClickListener) {
		rlNotComplaeList.setOnClickListener( translateClickListener);
	}
	
	public void setAdapter(ListAdapter listAdapter) {
		contentListView.setAdapter(listAdapter);
	}
	
	public ListAdapter getAdapter() {
		return contentListView.getAdapter();
	}
	
	public TextView getLeftTextView() {
		return translateFinishedTextView;
	}
	
	public TextView getRightTextView() {
		return translateNotFinishedTextView;
	}
	
	public View getLeftContainer() {
		return rlHasComplaeList;
	}
	
	public View getRightContainer() {
		return rlNotComplaeList;
	}

	public void lightCompletedBg(){
		rlHasComplaeList.setBackgroundColor(getResources().getColor(R.color.white_button_bg));
		rlNotComplaeList.setBackgroundColor(getResources().getColor(R.color.head));
	}
	
	public void lightUnCompletedBg(){
		rlNotComplaeList.setBackgroundColor(getResources().getColor(R.color.white_button_bg));
		rlHasComplaeList.setBackgroundColor(getResources().getColor(R.color.head));
	}
	
}
